package public

import (
	"server/game/model"
	"server/share"
	"server/social/handle"

	"github.com/hwcer/yyds/context"
)

func init() {
	fri := &handle.Friend{}
	Register(fri)
	//接口兼容
	Register(fri.Apply, "friend", "Add")
	Register(fri.Remark, "friend", "SetBakName")
	//Register(fri.Like, "friend", "like")
	Register(SearchFriend, "friend", "Search")
	Register(fri.Recommend, "friend", "RecommendFriend")
}

/**
 * @name search 好友搜索
 * @param string name 玩家昵称
 * @param string uid 玩家唯一标识,有uid优先以uid为准
 * @param string key 额外字段,多个以","分割
 * 好友搜索
 */
func SearchFriend(c *context.Context) any {
	uid := c.GetString("uid")
	name := c.GetString("name")
	var data []*share.Player
	tx := db.Model(&model.Role{})
	if uid != "" {
		tx = tx.Where(uid)
	} else if name != "" {
		tx = tx.Where("name = ?", name)
	}
	if err := tx.Find(&data).Error; err != nil {
		return err
	}
	return data
}
